package com.aitaoxue.palx.ui;

import org.apache.http.Header;

import android.view.View;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.TextView;
import butterknife.InjectView;

import com.aitaoxue.palx.R;
import com.aitaoxue.palx.api.remote.AitaoXueApi;
import com.aitaoxue.palx.base.BaseActivity;
import com.aitaoxue.palx.bean.MoneyAndScore;
import com.aitaoxue.palx.bean.UserInfo;
import com.aitaoxue.palx.util.GsonUtil;
import com.loopj.android.http.AsyncHttpResponseHandler;

public class MoneyAndPointActivity extends BaseActivity {

	@InjectView(R.id.money)
	TextView money;
	@InjectView(R.id.point)
	TextView point;

	@Override
	protected boolean hasBackButton() {
		return true;
	}

	@Override
	protected int getActionBarTitle() {
		return R.string.my_account;
	}

	@Override
	protected int getLayoutId() {
		return R.layout.fragment_money_and_point;
	}

	@Override
	public void onClick(View v) {
	}

	@Override
	public void initView() {
		Animation anim=AnimationUtils.loadAnimation(this, R.anim.course_item_in);
		money.setAnimation(anim);
		point.setAnimation(anim);
		
		getAccountNum();
	}

	@Override
	public void initData() {
		// TODO Auto-generated method stub

	}

	private void getAccountNum() {
		AitaoXueApi.getTeacherMoney(moneyHandler);
	}

	private AsyncHttpResponseHandler moneyHandler = new AsyncHttpResponseHandler() {

		@Override
		public void onSuccess(int arg0, Header[] arg1, byte[] arg2) {
			String result = new String(arg2);
			UserInfo userInfo = GsonUtil.GsonToBean(result, UserInfo.class);
			MoneyAndScore res = userInfo.getContent();
			
			money.setText("￥"+res.getProd_acnt_num());
			point.setText(res.getProd_acnt_gold());
		}

		@Override
		public void onFailure(int arg0, Header[] arg1, byte[] arg2,
				Throwable arg3) {
			System.out.println("lalala");
		}
	};

}
